import java.util.*;

public class Josepus {
  public static void main(String[] args) {

    int n = 13;
    int m = 3;
    int point = 0;//指针
    int number = 1;//计数器
    ArrayList list = new ArrayList();
    for (int i = 1; i <= n; i++) {
     // 初始化链表
     list.add(new Integer(i));
    }
    while (list.size() > 1) {
     if (number % m == 0) {
      list.remove(point);
      point--;//如果有删除，指针指向前一个元素，可理解为没有做过删除
     }
     point++;// 指针后移
     number++;//计数器累加
     if (point > list.size()-1 ) {
      // 指针越界重新开始
      point = 0;
     }
    }
    System.out.println(list.get(0));
   }
}